/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mirza
 */
public class PelaporanBarang extends DatabaseModel {
    private String kodePelaporanBarang;
    private String kodeBarang;
    private String nipPelapor;
    private String tanggalLaporan;
    private String isiLaporan;

    public PelaporanBarang() {
        super();
    }

    @Override
    public boolean insertTransaction() {
        try {
            String sql = "insert into pelaporan_barang(`kode_barang`,`nip_pelapor`,`tanggal_laporan`,`isi_laporan`) values('" + kodeBarang + "','" + nipPelapor + "','" + tanggalLaporan + "','" + isiLaporan + "')";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean updateTransaction() {

        try {
            String sql = "update pelaporan_barang set kode_barang = '"+kodeBarang+"', nip_pelapor = '"+nipPelapor+"', tanggal_laporan = '"+tanggalLaporan+"', isi_laporan = '"+isiLaporan+"' where kode_pelaporan_barang = '"+kodePelaporanBarang+"'";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PelaporanBarang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean deleteTransaction() {
        try {
            String sql = "delete from pelaporan_barang where kode_pelaporan_barang = '" + kodePelaporanBarang + "'";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public ResultSet getData(String filter) {
        try {
            String sql = "select * from v_pelaporan_barang " + filter;
            return super.statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Suplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    /**
     * @param kodePelaporanBarang the kodePelaporanBarang to set
     */
    public void setKodePelaporanBarang(String kodePelaporanBarang) {
        this.kodePelaporanBarang = kodePelaporanBarang;
    }

    /**
     * @param kodeBarang the kodeBarang to set
     */
    public void setKodeBarang(String kodeBarang) {
        this.kodeBarang = kodeBarang;
    }

    /**
     * @param nipPelapor the nipPelapor to set
     */
    public void setNipPelapor(String nipPelapor) {
        this.nipPelapor = nipPelapor;
    }

    /**
     * @param tanggalLaporan the tanggalLaporan to set
     */
    public void setTanggalLaporan(String tanggalLaporan) {
        this.tanggalLaporan = tanggalLaporan;
    }

    /**
     * @param isiLaporan the isiLaporan to set
     */
    public void setIsiLaporan(String isiLaporan) {
        this.isiLaporan = isiLaporan;
    }
}
